home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / glibc-1.09 / glibc-1 / glibc-1.09.1 / sysdeps / standalone / i386 / force_cpu386 / console.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-25  |  4.6 KB  |  164 lines

  1. /* Copyright (C) 1994 Free Software Foundation, Inc.
  2.    Contributed by Joel Sherrill (jsherril@redstone-emh2.army.mil),
  3.      On-Line Applications Research Corporation.
  4.  
  5. This file is part of the GNU C Library.
  6.  
  7. The GNU C Library is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU Library General Public License as
  9. published by the Free Software Foundation; either version 2 of the
  10. License, or (at your option) any later version.
  11.  
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. Library General Public License for more details.
  16.  
  17. You should have received a copy of the GNU Library General Public
  18. License along with the GNU C Library; see the file COPYING.LIB.  If
  19. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  20. Cambridge, MA 02139, USA.  */
  21.  
  22. #include <ansidecl.h>
  23. #include <standalone.h>
  24. #include "__i386.h"
  25.  
  26. /* Console IO routines for a FORCE CPU386 board. */
  27.  
  28. /* Force CPU/386 specific IO addressing
  29.  *
  30.  * The following determines whether Port B or the Console should
  31.  * be used for console I/O.  Setting ONE (and only ONE) of these to 1
  32.  * enables I/O on that port.
  33.  * 
  34.  *     PORT A - DUSCC MC68562 Channel A  (*** not supported here ***)
  35.  *     PORT B - DUSCC MC68562 Channel B
  36.  *     PORT C - MFP MC68901 Channel      (*** FORCEbug console ***)
  37.  */
  38.  
  39. #define PORTB         1               /* use port b as console */
  40. #define PORTC         0               /* use console port as console */
  41.  
  42. #if ( PORTB == 1 )
  43. #define TX_STATUS     0x1b6           /* DUSCC General Status Register */
  44. #define RX_STATUS     0x1b6           /* DUSCC General Status Register */
  45. #define TX_BUFFER     0x1e0           /* DUSCC Transmitter Channel B */
  46. #define RX_BUFFER     0x1e8           /* DUSCC Receiver Channel B */
  47. #define Is_tx_ready( _status ) ( (_status) & 0x20 )
  48. #define Is_rx_ready( _status ) ( (_status) & 0x10 )
  49. #endif
  50.  
  51. #if ( PORTC == 1 )
  52. #define TX_STATUS     0x12c           /* MFP Transmit Status Register */
  53. #define RX_STATUS     0x12a           /* MFP Receive Status Register */
  54. #define TX_BUFFER     0x12e           /* MFP Transmitter Channel  */
  55. #define RX_BUFFER     0x12e           /* MFP Receiver Channel  */
  56. #define Is_tx_ready( _status ) ( (_status) & 0x80 )
  57. #define Is_rx_ready( _status ) ( (_status) & 0x80 )
  58. #endif
  59.    
  60. /* _Console_Initialize
  61.  
  62. On the Force board the console require some initialization. */
  63.  
  64. void
  65. DEFUN_VOID(_Console_Initialize)
  66. {
  67.   register unsigned8 ignored;
  68.  
  69.   /* FORCE technical support mentioned that it may be necessary to
  70.      read the DUSCC RX_BUFFER port four times to remove all junk.
  71.      This code is a little more paranoid.  */
  72.  
  73.   inport_byte( RX_BUFFER, ignored );
  74.   inport_byte( RX_BUFFER, ignored );
  75.   inport_byte( RX_BUFFER, ignored );
  76.   inport_byte( RX_BUFFER, ignored );
  77.   inport_byte( RX_BUFFER, ignored );
  78. }
  79.  
  80. /* Miscellaneous support for console IO */
  81.  
  82. static inline int _Force386_is_rx_ready()
  83. {
  84.   register unsigned8 status;
  85.  
  86.   inport_byte( RX_STATUS, status );
  87.  
  88.   if ( Is_rx_ready( status ) ) return 1;
  89.   else                         return 0;
  90. }
  91.  
  92. static inline int _Force386_is_tx_ready()
  93. {
  94.   register unsigned8 status;
  95.  
  96.   inport_byte( TX_STATUS, status );
  97.  
  98.   if ( Is_tx_ready( status ) ) return 1;
  99.   else                         return 0;
  100. }
  101.  
  102.  
  103. static inline int _Force386_read_data()
  104. {
  105.   register unsigned8 ch;
  106.  
  107. #if ( PORTB == 1 )
  108.     /* Force example code resets the Channel B Receiver here.
  109.      * It appears to cause XON's to be lost.
  110.      */  
  111.  
  112.      /* outport_byte( RX_STATUS, 0x10 );  */
  113. #endif
  114.  
  115.   inport_byte( RX_BUFFER, ch );
  116.  
  117.   return ch;
  118. }
  119.  
  120. /* _Console_Putc
  121.  
  122. This routine transmits a character.  It supports XON/XOFF flow control.  */
  123.  
  124. #define XON             0x11            /* control-Q */
  125. #define XOFF            0x13            /* control-S */
  126.  
  127. int
  128. DEFUN( _Console_Putc, (ch), char ch )
  129. {
  130.   register unsigned8 inch;
  131.  
  132.   while ( !_Force386_is_tx_ready() );
  133.  
  134.   while ( _Force386_is_rx_ready() == 1 ) {      /* must be an XOFF */
  135.     inch = _Force386_read_data();
  136.     if ( inch == XOFF )
  137.       do {
  138.         while ( _Force386_is_rx_ready() == 0 );
  139.         inch = _Force386_read_data();
  140.       } while ( inch != XON );
  141.   }
  142.  
  143.   outport_byte( TX_BUFFER, ch );
  144.   return( 0 );
  145. }
  146.  
  147. /* _Console_Getc
  148.  
  149. This routine reads a character from the UART and returns it. */
  150.  
  151. int
  152. DEFUN( _Console_Getc, (poll), int poll )
  153. {
  154.   if ( poll ) {
  155.     if ( !_Force386_is_rx_ready() )
  156.       return -1;
  157.     else
  158.       return _Force386_read_data();
  159.   } else {
  160.     while ( !_Force386_is_rx_ready() );
  161.     return _Force386_read_data();
  162.   }
  163. }
  164.